<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">

    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <link rel="stylesheet" th:href="@{/css/font.css}"/>
        <link rel="stylesheet" th:href="@{/css/xadmin.css}"/>

        <script type="text/javascript" th:src="@{/js/jquery.min.3.2.1.js}"></script>
        <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
        <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>

        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
        <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
        <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>

    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">系统管理</a>
                <a>
                    <cite>权限管理</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header" sec:authorize="hasRole('SYS_MENU_ADD')">
                            <button class="layui-btn" onclick="xadmin.open('添加一级菜单','/sys/menu/to/add/0/1')"><i class="layui-icon"></i>添加一级菜单</button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                                <thead>
                                    <tr>
                                        <th width="130">ID</th>
                                        <th>菜单</th>
                                        <th width="150">链接</th>
                                        <th width="200">权限</th>
                                        <th width="150">等级</th>
                                        <th width="80">状态</th>
                                        <th width="250">操作</th>
                                    </tr>
                                </thead>
                                <tbody class="x-cate">
                                    <tr th:cate-id='${item.id}' th:fid='${item.getPId()}' th:each="item,itemStat : ${list}">
                                        <td th:text="${item.id}"></td>
                                        <td th:if="${item.level==1}"><i class="layui-icon x-show" status='false'>&#xe623;</i><span th:text="${item.name}"></span></td>
                                        <td th:if="${item.level==2}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i class="layui-icon x-show" status='false'>&#xe623;</i><span th:text="${item.name}"></span></td>
                                        <td th:if="${item.level==3}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├<span th:text="${item.name}"></span></td>
                                        <td th:text="${item.url}"></td>
                                        <td th:text="${item.authority.length()>5?item.authority.substring(5):item.authority}"></td>
                                        <td th:if="${item.level==1}">一级菜单</td>
                                        <td th:if="${item.level==2}">二级菜单</td>
                                        <td th:if="${item.level==3}">功能按钮</td>
                                        <td sec:authorize="!hasRole('SYS_MENU_ENABLE')" th:text="${item.enable==1?'启用':'停用'}"></td>
                                        <td th:if="${item.enable==1}" sec:authorize="hasRole('SYS_MENU_ENABLE')"><input type="checkbox" th:value="${item.id}" lay-filter="switchID" name="switch"  lay-text="启用|停用" checked="checked" lay-skin="switch"></td>
                                        <td th:if="${item.enable==0}" sec:authorize="hasRole('SYS_MENU_ENABLE')"><input type="checkbox" th:value="${item.id}" lay-filter="switchID" name="switch"  lay-text="启用|停用" lay-skin="switch"></td>
                                        <td class="td-manage">
                                            <button class="layui-btn layui-btn layui-btn-xs"  th:onclick="'xadmin.open(\'编辑\',\'/sys/menu/to/update/'+${item.id}+'\')'" sec:authorize="hasRole('SYS_MENU_UPDATE')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                            <button th:if="${item.level<=2}" class="layui-btn layui-btn-warm layui-btn-xs"  th:onclick="'xadmin.open(\'添加子菜单\',\'/sys/menu/to/add/'+${item.id}+'/'+${item.level+1}+'\')'" sec:authorize="hasRole('SYS_MENU_ADD')"><i class="layui-icon">&#xe642;</i>添加子栏目</button>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>
            layui.use(['form'], function(){
                form = layui.form;

            });

            /*用户-删除*/
            function member_del(obj,id){
                layer.confirm('确认要删除吗？',function(index){
                    //发异步删除数据
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                });
            }

            // 分类展开收起的分类的逻辑
            //
            $(function(){
                $("tbody.x-cate tr[fid!='0']").hide();
                // 栏目多级显示效果
                $('.x-show').click(function () {
                    if($(this).attr('status')=='true'){
                        $(this).html('&#xe625;');
                        $(this).attr('status','false');
                        cateId = $(this).parents('tr').attr('cate-id');
                        $("tbody tr[fid="+cateId+"]").show();
                    }else{
                        cateIds = [];
                        $(this).html('&#xe623;');
                        $(this).attr('status','true');
                        cateId = $(this).parents('tr').attr('cate-id');
                        getCateId(cateId);
                        for (var i in cateIds) {
                            $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
                        }
                    }
                })
            })

            var cateIds = [];
            function getCateId(cateId) {
                $("tbody tr[fid="+cateId+"]").each(function(index, el) {
                    id = $(el).attr('cate-id');
                    cateIds.push(id);
                    getCateId(id);
                });
            }

        </script>
        <script>
            layui.use(['form'], function(){
                var form = layui.form;
                form.on('switch(switchID)', function(data){
                    var id = data.elem.value;
                    if(this.checked){
                        $.post("/sys/menu/enable/"+id+"/1", function(data,status){
                            layer.msg('已启用!',{icon:1,time:1000});
                        });
                    }else{
                        $.post("/sys/menu/enable/"+id+"/0", function(data,status){
                            layer.msg('已停用!',{icon:1,time:1000});
                        });
                    }
                });
            });
        </script>
    </body>
</html>
